﻿using System.Data;

namespace Randomgame
{/// <summary>
/// TestOfReaction
/// </summary>
    internal class Program
    {
        enum Direction
        {
            Up,
            Down,
            Left,
            Right
        }
        const int countOfTest = 5;
        static void Main(string[] args)
        {
            Program.KeyReaction();
        }
        /// <summary>
        /// key game
        /// </summary>
        
        private static void KeyReaction()//  函数类型 function   public可以被外部成员调用 private只能被类的成员调用 
        {
            double reactionTime = 0;
            int countOfError = 0;
            Random rnd = new Random();
            for (int i = 0; i < countOfTest; i++)
            {
                //记录测试前时间
                DateTime startTime = DateTime.Now;
                //清屏
                Console.Clear();
                Console.WriteLine($"现在是第{i}次测试，总耗时{reactionTime}秒，共错误{countOfError}次");
                //随机生成四个方向
                Direction direction = (Direction)rnd.Next(0, 4);
                //屏幕显示随机生成的方向
                Console.WriteLine(direction.ToString());
                bool flag = false;

                do
                {
                    ConsoleKeyInfo input = Console.ReadKey();
                    switch (direction)
                    {
                        case Direction.Up:
                            if (input.Key == ConsoleKey.UpArrow) flag = true;
                            else
                            {
                                countOfError++;
                            }
                            break;
                        case Direction.Down:
                            if (input.Key == ConsoleKey.DownArrow) flag = true;
                            else
                            {
                                countOfError++;
                            }
                            break;
                        case Direction.Left:
                            if (input.Key == ConsoleKey.LeftArrow) flag = true;
                            else
                            {
                                countOfError++;
                            }
                            break;
                        case Direction.Right:
                            if (input.Key == ConsoleKey.RightArrow) flag = true;
                            else
                            {
                                countOfError++;
                            }
                            break;

                    }
                } while (flag == false);//如果输入错误，则继续输入
                //记录测试后时间
                DateTime afterTime = DateTime.Now;
                //累加反应时间
                reactionTime += (afterTime - startTime).TotalSeconds;
            }
            Console.ReadKey();
        }
    }
}